package es.ats.codington.festival.services;


import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import es.ats.codington.festival.daos.EventSignUpDAOImp;
import es.ats.codington.festival.domain.Event;
import es.ats.codington.festival.domain.EventSignUp;
import es.ats.codington.festival.domain.Place;
import es.ats.codington.festival.exceptions.ServiceException;
import es.ats.codington.festival.interfaces.services.IEventSignUpService;
import es.ats.codington.festival.utils.FERSDataConnection;


public class EventSignUpService implements IEventSignUpService {
	
	private EventSignUpDAOImp esd ;
	private static EventSignUp esu;
	
	//Constructor
	
	public EventSignUpService() {
		super();
		esd=new EventSignUpDAOImp();
		esu=new EventSignUp();
	}

	
	public EventSignUpService(EventSignUpDAOImp esd, EventSignUp esu) {
		super();
		this.esd = esd;
		this.esu = esu;
	}
	
	

	public EventSignUpDAOImp getEsd() {
		return esd;
	}


	public void setEsd(EventSignUpDAOImp esd) {
		this.esd = esd;
	}


	public EventSignUp getEv() {
		return esu;
	}


	public void setEv(EventSignUp esu) {
		this.esu = esu;
	}

	
	
	//CORRECTO
	
	@Override
	public boolean isRegisteredToEvent(EventSignUp esu)  throws ServiceException {
		
		
		FERSDataConnection fdc=esd.getCon();
		try{
			fdc.connect();
			boolean aux=esd.isRegisteredToEvent(esu);
			fdc.disconnect();
			return aux;  	
		}
		catch (Exception ex) {
			fdc.disconnect();
			throw new ServiceException("DB isRegister failure:"+ex.getMessage(), ex);
		}
		
	}
	

	
	@Override
	public List<Event> viewEventsOfUserDAO(int visitorId) throws ServiceException {
		
		FERSDataConnection fdc=esd.getCon();
		try{
			fdc.connect();
			List<Event> list=esd.viewEventsOfUserDAO(visitorId);
			fdc.disconnect();
			return list;
		}
		catch (Exception ex) {
			throw new ServiceException("DB viewEvent failure:"+ex.getMessage(), ex);
		}
	}
			
	
	//CORRECTO
	@Override
	public int updateRestSeatsAvailableEvent(Event ev) throws ServiceException {
		
		FERSDataConnection fdc=esd.getCon();
		try{
			fdc.connect();
			int a=esd.updateRestSeatsAvailableEvent(ev);
			fdc.disconnect();
			return a;
		}
		catch (Exception ex) {
			throw new ServiceException("DB updateSeats failure:"+ex.getMessage(), ex);
		}
	}
	
	
	//CORRECTO
	@Override
	public int registerVisitorForNewEventDAO(EventSignUp esu) throws ServiceException {
		
		
		FERSDataConnection fdc=esd.getCon();
		try{
			fdc.connect();
			int a=esd.registerVisitorForNewEventDAO(esu);
			fdc.disconnect();
			return a;
		}
		catch (Exception ex) {
			throw new ServiceException("DB register failure:"+ex.getMessage(), ex);
		}
	}
	
	
	//CORRECTO----->
	@Override
	public int unregisterVisitorForEventDAO(EventSignUp esu)  throws ServiceException {
		
		FERSDataConnection fdc=esd.getCon();
		try{
			fdc.connect();
			int a=esd.unregisterVisitorForEventDAO(esu);
			fdc.disconnect();
			return a;
		}
		catch (Exception ex) {
			throw new ServiceException("DB unRegister failure:"+ex.getMessage(), ex);
		}
	}
	
	
	
}
